home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15081 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  59 lines

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: dos.h equivalent in gcc or cc ?
  5. Date: 16 Apr 1996 15:42:40 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Distribution: inet
  8. Message-ID: <4l17p0INNf6v@keats.ugrad.cs.ubc.ca>
  9. References: <3173B701.41C6@ieec.fcr.es>
  10. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  11.  
  12. In article <3173B701.41C6@ieec.fcr.es>, Oscar Chic  <chic@ieec.fcr.es> wrote:
  13. >I'm trying to pass arguments to a function with _argv and _argc
  14. >global variables that Borland 4.5 permits.
  15.  
  16. ...and which are not portable anywhere, really.
  17.  
  18. >In Borland you must do an include of dos.h
  19. >Which is the equivalent in gcc or cc in a UNIX WS ?
  20.  
  21. It's called...
  22.  
  23.     int main(int argc, char **argv)
  24.  
  25. >Which file must I include to do the same ?
  26.  
  27. None. Just declare a pair of external variables (outside of any function, of
  28. course)
  29.  
  30. int global_argc;
  31. char **global_argv;
  32.  
  33.  
  34. Make these known to other programs with appropriate ``extern'' declarations in
  35. your own private header.
  36.  
  37. Then, inside the main() function, simply assign the arguments to these:
  38.  
  39. int main(int argc, char **argv)
  40.  
  41. {
  42.     global_argc = argc;
  43.     global_argv = argv;
  44.  
  45.     .
  46.     .
  47.     .
  48.  
  49. }
  50.  
  51. This is portable, so you don't have to worry when you port away from the
  52. Borland environment.
  53.  
  54. Declaring your own identifiers that begin with _ is illegal according to the C
  55. language standard, so in order to make Borland's mechanism work elsewhere you
  56. would have to violate the standard.
  57. -- 
  58. I'm not really a jerk, but I play one on Usenet.
  59.